﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using Model;
using Ysb.Components;
public partial class Admin_UserManage : System.Web.UI.Page
{
    UserService users = new UserService();
    User user = new User();
    const string vsKey = "usrsearchCriteria";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (AdminCheck.Check(this, 37))
        {

            if (!Page.IsPostBack)
            {
                BindDLL();
                DataLoad(string.Empty);
            }
        }
        else
        {
            Response.Redirect(AdminCheck.RedirectPage);
        }

    }
    private void BindDLL()
    {
        sele.DataSource = new PublicSqlService().GetData("*", "Tb_SalesUer", "");
        sele.DataTextField = "Name";
        sele.DataValueField = "ID";
        sele.DataBind();
        sele.Items.Insert(0, "");
    }
    private void DataLoad(string sqlnew)
    {
        ViewState[vsKey] = sqlnew;
        if (sqlnew != null && sqlnew.Trim() != "")
        {
            sqlnew = "  1=1 and overlimit=0 " + sqlnew; //AccountNo is not Null
        }
        else
        {
            sqlnew = "  1=1 and overlimit=0 "; //AccountNo is not Null
        }
        int count = users.GetUserCount(sqlnew);
        NewsPage.RecordCount = count;
        BindData(sqlnew);

    }
    private void BindData(string s)
    {
        string words = "Uid,QQ,IDCardNo,isnull(UPEXCompanyID,1) as UPEXCompanyID, LoginName,PassWord,TrueName,Email,Country,State,City,Address,Tel,Mobile,FaxNo,Company,ZIPCode,Sex,UserState,UnexState,PayMode,PostTime,LastLoginTime,isnull(UserType,0) as UserType , isnull(AccountNo,'') as AccountNo,CountryID,StateID,Rights";

        userlist.DataSource = users.GetAllUser("TblUserInfo", NewsPage.RecordCount, NewsPage.PageSize, NewsPage.CurrentPageIndex, "Uid", 1, true, words, s);

        userlist.DataBind();

    }
    protected void NewsPage_PageChanged(object sender, EventArgs e)
    {
        DataLoad((string)ViewState[vsKey]);
    }


    protected void searchbtn_Click(object sender, ImageClickEventArgs e)
    {
        NewsPage.CurrentPageIndex = 1;
        string sql = "  ";


        if (loginnametxt.Text.Trim() != "")
        {
            sql += " and LoginName='" + loginnametxt.Text.Trim() + "'";
        }

        if (realnametxt.Text.Trim() != "")
        {
            sql += " and TrueName like '%" + realnametxt.Text.Trim() + "%'";
        }

        if (teltxt.Text.Trim() != "")
        {
            sql += " and Tel like '%" + teltxt.Text.Trim() + "%'";
        }

        if (sele.SelectedValue.Trim() != "")
        {
            sql += " and  UserType=" + sele.SelectedValue;
        }

        if (acid.Text.Trim() != "")
        {
            sql += " and AccountNo='" + acid.Text.Trim() + "'";
        }

        if (waitck.Checked == true)
        {
            sql += " and  UserState =0";

        }
        sql += " and  overlimit=0";

        DataLoad(sql);
    }
}
